home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 034a / twview82.zip / MISC.INC < prev    next >
Text File  |  1991-02-04  |  3KB  |  108 lines

  1. function die( size : integer ) : integer;
  2. begin
  3.   die := random( size ) + 1;
  4. end;
  5.  
  6. function prompt( p : string ) : boolean;
  7. { returns true if they say yes }
  8. var
  9.   ch : char;
  10. begin
  11.   write(p);
  12.   readln( ch );
  13.   prompt := ch in ['Y','y'];
  14. end; {again}
  15.  
  16. function min( a, b : integer ) : integer;
  17. begin
  18.   if a > b then
  19.     min := b
  20.   else
  21.     min := a;
  22. end;
  23.  
  24. function minreal( a, b : real ) : real;
  25. begin
  26.   if a > b then
  27.     minreal := b
  28.   else
  29.     minreal := a;
  30. end; {minreal}
  31.  
  32. function IsWarp( from, OverTo : sector ) : boolean;
  33. { true if you can go from from to OverTo in one step }
  34. var
  35.   t : warpIndex;
  36. begin
  37.   IsWarp := false;
  38.   if space.sectors[ from ].number <> UnExplored then
  39.     for t := 1 to space.sectors[ from ].number do
  40.       if space.sectors[ from ].data[t] = OverTo then
  41.         IsWarp := true;
  42. end; {IsWarp}
  43.  
  44. procedure FixDistances( sec : sector; var D : distanceArray );
  45. { D[j].d = distance from sec;
  46.   D[j].s = one node close }
  47. var
  48.   s : sector;
  49.   breadth : queue;
  50.   daddy, sonny : sector;
  51.   i : warpindex;
  52. begin
  53.    writeln('Computing distances...');
  54.   for s := 1 to maxSector do
  55.     D[s].d := -1;
  56.   breadth.front := 0;
  57.   enqueue( breadth, sec, sec );
  58.   while breadth.front > 0 do
  59.     begin
  60.       serve( breadth, daddy, sonny );
  61.       if D[ sonny ].d = -1 then {haven't hit him before:}
  62.         begin
  63.           D[ sonny ].d := D[ daddy ].d + 1;
  64.           D[ sonny ].s := daddy;
  65.           with space.sectors[ sonny ] do if number > 0 then
  66.             for i := 1 to number do
  67.               enqueue( breadth, sonny, data[ i ] );
  68.         end; {if}
  69.     end; {while}
  70.   for s := 1 to maxSector do if D[s].d = -1 then D[s].d := maxint;
  71. end; {FixDistances}
  72.  
  73. function GetSector : SectorIndex;
  74. var
  75.   s : integer;
  76. begin
  77.   repeat
  78.     write('Sector? [0 to abort]  ');
  79.     readln( s );
  80.   until (s>=0) and (s<=MaxSector);
  81.   GetSector := s;
  82. end; {GetSector}
  83.  
  84. function LogToDisk( var f : text; message : string ) : boolean;
  85. var
  86.   filename : string;
  87.   ch       : char;
  88. begin
  89.   if not prompt( message ) then
  90.     LogToDisk := false
  91.   else
  92.     begin
  93.       LogToDisk := true;
  94.       write('Name of file for log? ');
  95.       readln( filename );
  96.       assign( f, filename );
  97.       rewrite( f );
  98.     end; {else}
  99. end; {LogToDisk}
  100.  
  101. function upcase( ch : char ) : char;
  102. { if letter in 'a'..'z' give upper case equivalent }
  103. begin
  104.   if ch in ['a'..'z'] then
  105.     upcase := chr( ord( ch ) - ord('a') + ord('A') )
  106.   else
  107.     upcase := ch;
  108. end; {upcase}